package com.zhuiYun.project.api.classifyshops.service.impl;

import com.zhuiYun.project.api.classifyshops.entity.BigClassify;
import com.zhuiYun.project.api.classifyshops.entity.Classify;
import com.zhuiYun.project.api.classifyshops.entity.CommodityComment;
import com.zhuiYun.project.api.classifyshops.mapper.ClassifyMapper;
import com.zhuiYun.project.api.classifyshops.service.ClassifyService;
import com.zhuiYun.project.api.commoditydetail.entity.Commodity;
import com.zhuiYun.project.util.pageUtil.MybatisPageHelper;
import com.zhuiYun.project.util.pageUtil.PageRequest;
import com.zhuiYun.project.util.pageUtil.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.DoubleSummaryStatistics;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName ClassifyServiceimpl
 * @Description TODO 商品分类实现类
 * @Author 韩佳轩
 * @Date 2023/4/6 10:33
 **/
@Service
public class ClassifyServiceimpl implements ClassifyService {
    @Autowired
    ClassifyMapper classifyMapper;


    /**
    * @Author 韩佳轩
    * @Description 全查大分类
    * @Date 2023/4/17 15:22
    * @Return java.util.List<com.zhuiYun.project.api.classifyshops.entity.BigClassify>
    * @param bigClassify
    */

    @Override
    public List<BigClassify> getBigClassify(BigClassify bigClassify) {
        return classifyMapper.getBigClassify(bigClassify);
    }

    /**
     * @param classify
     * @Author 韩佳轩
     * @Description 根据大分类id查小分类
     * @Date 2023/4/6 14:43
     * @Return java.util.List<com.zhuiYun.project.api.classifyshops.entity.Classify>
     */

    @Override
    public List<Classify> getClassify(Classify classify) {
        List<Classify> classify1 = classifyMapper.getClassify(classify);
        return classify1;
    }

    /**
     * @Author 韩佳轩
     * @Description 根据小分类查商品列表
     * @Date 2023/4/6 14:43
     * @Return java.util.List<com.zhuiYun.project.api.classifyshops.entity.Commodity>
     */
    @Override
    public List<Commodity> getComodityList(Commodity commodity) {
        return classifyMapper.getComodityList(commodity);
    }


    /**
     * @Author 韩佳轩
     * @Description 根据商品列表查商品详情
     * @Date 2023/4/6 19:39
     * @Return java.util.List<com.zhuiYun.project.api.classifyshops.entity.Commodity>
     */
    @Override
    public List<Commodity> getShopsMain(Commodity commodity) {
        return classifyMapper.getShopsMain(commodity);
    }


    /**
     * @param commodityComment
     * @param pageRequest
     * @Author 韩佳轩
     * @Description 商品详情下的评论全查
     * @Date 2023/4/9 19:25
     * @Return com.zhuiYun.project.util.pageUtil.PageResult
     */

    @Override
    public PageResult getShopsMaincomments(CommodityComment commodityComment, PageRequest pageRequest) {
        MybatisPageHelper.startPage(pageRequest);
//        //查询计算数据
//        DoubleSummaryStatistics aa = shopsMaincomments.stream().collect((Collectors.summarizingDouble(CommodityComment::getProductDescriptionRating)));
//        System.out.println(aa + "===============");
//        double sum=0.0;
//        for (CommodityComment cc:shopsMaincomments){
//            sum+=cc.getProductDescriptionRating();
//        }
//        double aa=sum/shopsMaincomments.size();
//        System.out.println(aa+"===============");
        PageResult pageResult = MybatisPageHelper.getPageResult(classifyMapper.getShopsMaincomments(commodityComment));
        return pageResult;
    }

    @Override
    public Double getScore(CommodityComment commodityComment) {
        List<CommodityComment> s = classifyMapper.getScore(commodityComment);
         //查询 计算出函数数据
        DoubleSummaryStatistics aa = s.stream().collect((Collectors.summarizingDouble(CommodityComment::getProductDescriptionRating)));
        System.out.println(aa + "===============");
        double average = aa.getAverage();
        return average;
    }
}
